require 'rake'

desc "Copy a class to a new class"
task :copyclass, :from, :to do |task, args|
  from, to = args[:from] + ".java", args[:to]
  unless File.exist? from and not File.exist?(to + ".java")
    raise "Source class does not exist OR destination file does!"
  end
  source = open(from, 'r') do |f| f.read end

  source = source.sub /public class (\w+)([^{]*)\s*\{/,
                  "public class #{to}\\2 {"
  open(to + ".java", "w") do |f|
    f.write source
  end
end
